<?php

require('init.php');

require(LIBWWWDIR . '/header.php');
require(LIBWWWDIR . '/forms.php');

echo "<h1>Problems Set</h1>\n\n";


function exist_file( $proid ){

//Registros existentes
	$conexion = connect();
	$query = "SELECT probid FROM set_problems WHERE probid = '".$proid."'";
	$res = mysql_query($query ,$conexion) or die(mysql_error());
	if( mysql_num_rows($res) != 0 ){
		return '<a href="see_Problem.php?pid=' .$proid .'">
			<img src="../images/pdf.png" title="See problem '.$proid.'" ></a>';
	}else{
		return '<img src="../images/fileclose.png" title="No avaible pdf archive to problem '.$proid.'" >';
	}
}

if( strcmp(now(), $cdata['starttime']) >= 0 && strcmp(now(), $cdata['endtime']) < 0){

	$res = $DB->q('TABLE SELECT probid,color FROM problem WHERE cid = %i',$cdata['cid']);
	
	if( count($res) == 0 ){
		echo "No problems defined";
	}else{
		//mostrar problemas de postmaratones solo a teams category post
		if($cdata['post']==1 && $teamdata['categoryid']==1){
			echo "No problems defined";
		}else{
			echo   "<table class=\"list sortable\">\n<thead>\n" .
			"<tr><th scope=\"col\">Problem</th>" .	
			"<th scope=\"col\">Statement</th>" .
			"</tr></thead>\n<tbody>\n"; 

			foreach( $res as $row ){	
				echo  '<tr><td class="probid">' .
				( !empty($row['color']) ?
			 	 '<img style="background-color: ' . htmlspecialchars($row['color']) .
			 	';" alt="problem colour ' . htmlspecialchars($row['color']) .
				'" src="../images/circle.png" /> ' : '' ) . 
				htmlspecialchars($row['probid']) .'</td><td>'. 
				exist_file( $row['probid'] ).' </td></tr>';	
			}
			echo "</tbody>\n</table>\n\n";
		}
	}
}else{
	echo "No contest active yet";
}
 




?>
